﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToRTR.CApExportToRTRExternalJoint
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ExportToRTR{

internal class CApExportToRTRExternalJoint : CApExportToRTRJoint
{
  private TxRobot m_robot;
  private bool m_parentJointExported;

  public CApExportToRTRExternalJoint(TxJoint joint, TxRobot robot)
    : base(joint)
  {
    this.m_joint = joint;
    this.m_robot = robot;
    this.m_parentJointExported = TxJoint.op_Inequality(this.m_joint.ParentLink.ParentJoint, (ITxObject) null) && ((Collection<ITxObject>) this.m_robot.ExternalAxes).Contains((ITxObject) this.m_joint.ParentLink.ParentJoint);
  }

  public override string GetJointName()
  {
    return $"{((ITxObject) this.m_joint.Device).Name}/{base.GetJointName()}";
  }

  public override string GetParentLinkName()
  {
    return this.m_parentJointExported ? $"{((ITxObject) this.m_joint.Device).Name}/{base.GetParentLinkName()}" : ((ITxObject) this.m_joint.Device).Name;
  }

  public override string GetChildLinkName()
  {
    return $"{((ITxObject) this.m_joint.Device).Name}/{base.GetChildLinkName()}";
  }

  public override TxJoint GetParentJoint()
  {
    return this.m_parentJointExported ? base.GetParentJoint() : CApExportToRTRUtils.GetRobotLastJoint(this.m_robot);
  }

  protected override void WriteIndex(CApExportToRTRXmlWriter writer)
  {
    writer.WriteStartElement("control");
    writer.WriteAttributeString("type", "additional_not_in_chain");
    writer.WriteAttributeString("command_index", this.Data.Index.ToString());
    writer.WriteEndElement();
  }
}
